import axios from "axios";
// import { useRouter } from "vue-router";
import { useUserStore } from "@/stores";
const userStore = useUserStore();
// const router = useRouter();

const baseURL = import.meta.env.VITE_BASE_URL;

const ins = axios.create({
    baseURL: baseURL,
});


// 设置 请求拦截
ins.interceptors.request.use((config) => {
    let token = userStore.getToken;
    if (token) {
        config.headers.Authorization = token
    }
    // 有的请求的请求时间比较长
    let longTimeRequest = ['/api/changePrivatePem']
    longTimeRequest.forEach(item => {
        if (item === config.url) {
            config.timeout = 30000;
        } else {
            config.timeout = 5000;
        }
    })
    return config;
}, (err) => {
    return Promise.reject(err);
});

// 设置响应拦截
ins.interceptors.response.use((res) => {
    // console.log('响应拦截');
    res = res.data;
    return res;
}, (err) => {
    return Promise.reject(err);
})

export default ins;
